import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"
import Layout from "@/layout/index.vue"

export const asyncRoutes: Array<RouteRecordRaw> = [
  {
    path: "/documentation",
    component: Layout, // 布局组件作为一级路由
    redirect: "/documentation/index",
    meta: {
      title: "Documentation",
      icon: "documentation",
      // alwaysShow: true,
    },
    children: [
      {
        path: "index",
        name: "Documentation",
        component: () => import("@/views/documentation/index.vue"),
        meta: {
          title: "Documentation",
          icon: "documentation",
          hidden: true,
        }
      }
    ]
  },
  {
    path: "/guide",
    component: Layout, // 布局组件作为一级路由
    redirect: "/guide/index",
    children: [
      {
        path: "index",
        name: "Guide",
        component: () => import("@/views/guide/index.vue"),
        meta: {
          title: "Guide",
          icon: "guide",
          // 默认加载Guide时，/documentation/index高亮显示
          activeMenu: "/documentation/index"
        }
      }
    ]
  },
  {
    path: "/system",
    component: Layout, // 布局组件作为一级路由
    redirect: "/system/user",
    meta: {
      title: "System",
      icon: "lock",
    },
    children: [
      {
        path: "menu",
        name: "Menu Management",
        component: () => import("@/views/system/menu.vue"),
        meta: {
          title: "Menu",
          icon: "list",
          // hidden: true,
        }
      },
      {
        path: "role",
        name: "Role Management",
        component: () => import("@/views/system/role.vue"),
        meta: {
          title: "Role",
          icon: "list",
        }
      },
      {
        path: "user",
        name: "User Management",
        component: () => import("@/views/system/user.vue"),
        meta: {
          title: "User",
          icon: "list",
        }
      }
    ]
  },
  {
    path: "/setting",
    component: Layout, // 布局组件作为一级路由
    redirect: "/setting/user",
    meta: {
      title: "Setting",
      icon: "lock",
    },
    children: [
      {
        path: "accSet",
        name: "accSet",
        component: () => import("@/views/setting/accSet.vue"),
        meta: {
          title: "AccSet",
          // icon: "list",
          // hidden: true,
        }
      },
      {
        path: "course",
        name: "course",
        component: () => import("@/views/setting/course.vue"),
        meta: {
          title: "Course",
          // icon: "list",
        }
      },
      {
        path: "beginPeriod",
        name: "beginPeriod",
        component: () => import("@/views/setting/beginPeriod.vue"),
        meta: {
          title: "BeginPeriod",
          // icon: "list",
        }
      },
      {
        path: "currency",
        name: "currency",
        component: () => import("@/views/setting/currency.vue"),
        meta: {
          title: "Currency",
          // icon: "list",
        }
      },
      {
        path: "voucherWord",
        name: "voucherWord",
        component: () => import("@/views/setting/voucherWord.vue"),
        meta: {
          title: "VoucherWord",
          // icon: "list",
        }
      },
      {
        path: "adjustAccount",
        name: "adjustAccount",
        component: () => import("@/views/setting/adjustAccount.vue"),
        meta: {
          title: "AdjustAccount",
          // icon: "list",
        }
      },
      {
        path: "voucherTemp",
        name: "voucherTemp",
        component: () => import("@/views/setting/voucherTemp.vue"),
        meta: {
          title: "VoucherTemp",
          // icon: "list",
        }
      },
      {
        path: "roleSet",
        name: "roleSet",
        component: () => import("@/views/setting/roleSet.vue"),
        meta: {
          title: "RoleSet",
          // icon: "list",
        }
      },
      {
        path: "bossAccount",
        name: "bossAccount",
        component: () => import("@/views/setting/bossAccount.vue"),
        meta: {
          title: "BossAccount",
          // icon: "list",
        }
      },
      {
        path: "backupRest",
        name: "backupRest",
        component: () => import("@/views/setting/backupRest.vue"),
        meta: {
          title: "BackupRest",
          // icon: "list",
        }
      },
      {
        path: "operationLog",
        name: "operationLog",
        component: () => import("@/views/setting/operationLog.vue"),
        meta: {
          title: "OperationLog",
          // icon: "list",
        }
      },
      {
        path: "importFromOther",
        name: "importFromOther",
        component: () => import("@/views/setting/importFromOther.vue"),
        meta: {
          title: "ImportFromOther",
          // icon: "list",
        }
      },
      {
        path: "reinitialize",
        name: "reinitialize",
        component: () => import("@/views/setting/reinitialize.vue"),
        meta: {
          title: "Reinitialize",
          // icon: "list",
        }
      }
    ]
  }
]

const constantRoutes: Array<RouteRecordRaw> = [
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        meta: {
          title: "Dashboard", // 需要配置声明文件否则无提示
          icon: "dashboard",
          affix: true,
          noCache: false,
        },
      },
    ]
  },
  {
    path: "/redirect",
    component: Layout,
    meta: {
      hidden: true
    },
    children: [
      {
        // 带参数的动态路由正则匹配 文档说明
        // https://next.router.vuejs.org/zh/guide/essentials/route-matching-syntax.html#%E5%8F%AF%E9%87%8D%E5%A4%8D%E7%9A%84%E5%8F%82%E6%95%B0
        path: "/redirect/:path(.*)", // 要匹配多级路由 应该加*号
        component: () => import("@/views/redirect/index.vue")
      }
    ]
  },
  {
    path: "/404",
    component: () => import("@/views/error-page/index.vue"),
    meta: {
      hidden: true // 404 hidden掉
    }
  },
  {
    path: "/home",
    component: () => import("../views/Home.vue")
  },
  {
    path: "/about",
    component: () => import("../views/About.vue")
  }
]

export const routes = [...constantRoutes, ...asyncRoutes];

export default createRouter({
  history: createWebHistory(),
  routes,
});